//
//  TKIMLoginView.m
//  TKIM
//
//  Created by liupm on 15/10/28.
//  Copyright © 2015年 liupm. All rights reserved.
//

#import "TKIMLoginView.h"
//#import "TKIMColorHelper.h"

@interface TKIMLoginView()



@end

@implementation TKIMLoginView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self drawView];
    }
    return self;
}


/**
 *  @Author lpm, 15-10-28 10:10:38
 *
 *  @brief  绘制界面
 */
-(void)drawView
{
    [self setupForDismissKeyboard];
    
    [self addSubview:self.accountTextField];
//    [self addSubview:self.pwdTextField];
    [self addSubview:self.registerButton];
    [self addSubview:self.loginButton];
}

-(UIButton *)registerButton
{
    if (!_registerButton)
    {
        _registerButton = [[UIButton alloc] initWithFrame:CGRectMake(self.accountTextField.frame.origin.x, self.accountTextField.frame.size.height+self.accountTextField.frame.origin.y+20, TKIMScreenWidth*0.3, 45)];
        _registerButton.layer.cornerRadius = 5.0f;
        _registerButton.titleLabel.font = [UIFont systemFontOfSize:18.0f];
        [_registerButton setTitle:@"消息中心" forState:UIControlStateNormal];
        [_registerButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_registerButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        _registerButton.backgroundColor = [TKIMColorHelper stringToColor:@"#50ADED"];
        _registerButton.tag = 1;
    }
    return _registerButton;
}


-(UIButton *)loginButton
{
    if (!_loginButton)
    {
        _loginButton = [[UIButton alloc] initWithFrame:CGRectMake(self.registerButton.frame.size.width+self.registerButton.frame.origin.x+10, self.registerButton.frame.origin.y, TKIMScreenWidth*0.47, 45)];
        _loginButton.layer.cornerRadius = 5.0f;
        _loginButton.titleLabel.font = [UIFont systemFontOfSize:18.0f];
        [_loginButton setTitle:@"登录" forState:UIControlStateNormal];
        [_loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_loginButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        _loginButton.backgroundColor = [TKIMColorHelper stringToColor:@"#E86D6F"];
        _loginButton.tag = 0;
    }
    return _loginButton;
}


-(UITextField *)accountTextField
{
    if (!_accountTextField)
    {
        _accountTextField = [[TKIMTextField alloc] initWithFrame:CGRectMake(TKIMScreenWidth*0.1, TKIMScreenHeight*0.05, TKIMScreenWidth*0.8, 40)];
        _accountTextField.placeholder = @"账号";
        _accountTextField.font = [UIFont systemFontOfSize:16.0f];
        _accountTextField.leftViewMode = UITextFieldViewModeAlways;
        _accountTextField.showUnderline = YES;
        _accountTextField.underlineColor = [TKIMColorHelper stringToColor:@"#cccccc"];
        _accountTextField.clearButtonMode = YES;
        _accountTextField.autocorrectionType = UITextAutocorrectionTypeNo;
        _accountTextField.autocapitalizationType=UITextAutocapitalizationTypeNone;

        UIButton *leftView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
        [leftView setImage:TKIMGetImage(@"im_icon_account") forState:UIControlStateNormal];
        leftView.imageEdgeInsets = UIEdgeInsetsMake(4, 6, 8, 6);
        _accountTextField.leftView = leftView;
        _accountTextField.keyboardType = UIKeyboardTypeAlphabet;
    }
    return _accountTextField;
}


-(UITextField *)pwdTextField
{
    if (!_pwdTextField)
    {
        _pwdTextField = [[TKIMTextField alloc] initWithFrame:CGRectMake(self.accountTextField.frame.origin.x, self.accountTextField.frame.size.height+self.accountTextField.frame.origin.y+5, TKIMScreenWidth*0.8, 40)];
        _pwdTextField.placeholder = @"密码";
        _pwdTextField.font = [UIFont systemFontOfSize:16.0f];
        _pwdTextField.secureTextEntry = YES;
        _pwdTextField.leftViewMode = UITextFieldViewModeAlways;
        _pwdTextField.showUnderline = YES;
        _pwdTextField.clearButtonMode = YES;
        _pwdTextField.underlineColor = [TKIMColorHelper stringToColor:@"#cccccc"];
        _pwdTextField.autocorrectionType = UITextAutocorrectionTypeNo;

        UIButton *leftView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
        [leftView setImage:TKIMGetImage(@"im_icon_pwd") forState:UIControlStateNormal];
        leftView.imageEdgeInsets = UIEdgeInsetsMake(4, 6, 8, 6);
        _pwdTextField.leftView = leftView;
    }
    return _pwdTextField;
}

@end
